{% import 'macros.html' as macros %}
<div class="gcb-nav left-menu" id="gcb-nav-y" role="navigation">
  <ul>
    {{course_info.unit.after_leftnav_begins | safe}}

    {% if not course_info.unit.show_unit_links_in_leftnav %}
        {% for unit, lessons, lesson_progress, pre_assessment, post_assessment in course_outline %}
            {% if unit_id == unit.unit_id %}
                {% if pre_assessment %}
                  {{ macros.render_a_unit_title(unit, pre_assessment, unit_progress,
                         is_progress_recorded, transient_student, can_see_drafts,
                         assessment and assessment.unit_id == pre_assessment.unit_id,
                         student_preferences) }}
                {% endif %}
                {% for lesson in lessons %}
                    {{ macros.render_lesson_title(
                         page_type, unit, lesson, lesson_progress, is_progress_recorded,
                         unit.unit_id == unit_id and lesson.lesson_id == lesson_id,
                         can_see_drafts) }}
                {% endfor %}
                {% if post_assessment %}
                  {{ macros.render_a_unit_title(unit, post_assessment, unit_progress,
                         is_progress_recorded, transient_student, can_see_drafts,
                         assessment and assessment.unit_id == post_assessment.unit_id,
                         student_preferences) }}
                {% endif %}
            {% endif %}
        {% endfor %}
    {% else %}
        {% for unit, lessons, lesson_progress, pre_assessment, post_assessment in course_outline %}
            {{ macros.render_u_unit_title(
                 unit, unit_progress, is_progress_recorded, transient_student,
                 can_see_drafts, unit.type != 'U',
                 'gcb-unit-title expanded'
                     if unit_id == unit.unit_id else 'gcb-unit-title'
                         if lessons else 'gcb-unit-title expanded leaf',
                 student_preferences) }}
            <div id="gcb-lesson-container"
                {% if unit_id == unit.unit_id %}
                    class="gcb-lesson-container expanded"
                {% else %}
                    class="gcb-lesson-container"
                {% endif %}>
            {% if pre_assessment %}
              {{ macros.render_a_unit_title(unit, pre_assessment, unit_progress,
                     is_progress_recorded, transient_student, can_see_drafts,
                     assessment and assessment.unit_id == pre_assessment.unit_id,
                     student_preferences) }}
            {% endif %}
            {% for lesson in lessons %}
                {{ macros.render_lesson_title(
                     page_type, unit, lesson, lesson_progress, is_progress_recorded,
                     unit.unit_id == unit_id and lesson.lesson_id == lesson_id,
                     can_see_drafts) }}
            {% endfor %}
            {% if post_assessment %}
              {{ macros.render_a_unit_title(unit, post_assessment, unit_progress,
                     is_progress_recorded, transient_student, can_see_drafts,
                     assessment and assessment.unit_id == post_assessment.unit_id,
                     student_preferences) }}
            {% endif %}
            </div>
        {% endfor %}
        <script>
            $('li.gcb-unit-title').click(function() {
                if ($(this).hasClass('leaf')) {
                    return;
                }
                if ($(this).hasClass('expanded')) {
                    $(this).removeClass('expanded');
                    $(this).next().removeClass('expanded');
                } else {
                    $(this).addClass('expanded');
                    $(this).next().addClass('expanded');
                }
            });
        </script>
    {% endif %}

    {{course_info.unit.before_leftnav_ends | safe}}
  </ul>
</div>
